package cn.dubito.seller.controller;

import cn.dubito.entity.Order;
import cn.dubito.seller.param.OrderParam;
import cn.dubito.seller.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author liliang
 * @description: 订单相关
 * @date 2018/5/29.
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    private static Logger LOG = LoggerFactory.getLogger(OrderController.class);

    @Autowired
    private OrderService orderService;

    /**
     * 下单
     *
     * @param param
     * @return
     */
    @PostMapping("/apply")
    public Order apply(@RequestHeader String authId, @RequestHeader String sign, @RequestBody OrderParam param) {
        LOG.info("申购请求参数:{}", param);
        Order order = new Order();
        BeanUtils.copyProperties(param, order);
        order = orderService.apply(order);
        LOG.info("申购返回结果:{}", order);
        return order;
    }
}
